package com.icode.web.controller.manager;

import com.icode.core.dto.house.RentDTO;
import com.icode.core.dto.manager.AssignmentDTO;
import com.icode.core.dto.order.PageDTO;
import com.icode.core.model.house.Assignment;
import com.icode.core.model.house.Rent;
import com.icode.service.house.HouseService;
import com.icode.service.management.AssignmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lb
 * Date: 15-12-14
 * Time: 下午5:22
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("assignmentback")
public class AssignmentBackController {

    @Autowired
    private AssignmentService assignmentService;
    @Autowired
    private HouseService houseService;

    @RequestMapping(value = "showall/{currentPage}/{status}", method = RequestMethod.GET)
    private String showall(@PathVariable String currentPage, @PathVariable String status, Model model) {
        String totalPage = houseService.findTotalPageByStatus(Assignment.class, status).toString();
        currentPage = PageDTO.isPage(currentPage, totalPage);
        List<AssignmentDTO> assignmentDTOs = assignmentService.findRentAllByPage(currentPage, status);
        model.addAttribute("assignmentDTOs", assignmentDTOs);
        model.addAttribute("totalPage", totalPage);
        model.addAttribute("currentPage", currentPage);
        model.addAttribute("status", status);
        return "back/assignment/assugnmentlist";
    }

    @RequestMapping(value = "assignmentdetails/{assignmentguid}",method = RequestMethod.GET)
    private  String  assignmentdetails(@PathVariable String assignmentguid,Model model ){
        AssignmentDTO assignmentDTO = houseService.getAssignmentDTO(assignmentguid);
        model.addAttribute("assignmentDTO",assignmentDTO);
        return "back/assignment/assugnmentlistDetails";
    }

}
